﻿using System;
using System.Text;
using System.IO;

namespace System.Security
{
    /// <summary>
    /// 
    /// </summary>
    public class MD5
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sInputString"></param>
        /// <returns></returns>
        public static string HashString(string sInputString)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();

            return BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(sInputString)));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sInputFilename"></param>
        /// <returns></returns>
        public static string HashFile(string sInputFilename)
        {
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();

            FileStream inFile = new System.IO.FileStream(sInputFilename, System.IO.FileMode.Open, System.IO.FileAccess.Read);

            var bInput = new byte[inFile.Length];

            inFile.Read(bInput, 0, bInput.Length);
            inFile.Close();

            return BitConverter.ToString(md5.ComputeHash(bInput));
        }
    }
}